include("shared.lua")
include("player_sh.lua")

function surface.ScreenScale( size )
	return size * ( ScrH() / 480.0 )
end
surface.SScale	= surface.ScreenScale
surface.CreateFont( "HUDIndicatorNumbers", { font = "HalfLife2", size = surface.SScale( 32 ) })
surface.CreateFont( "HUDIndicatorNumbersMedium", { font = "HalfLife2", size = surface.SScale( 24 ) })
surface.CreateFont( "HUDIndicatorNumbersSmall", { font = "HalfLife2", size = surface.SScale( 16 ) })

function GM:Initialize()
end

local function DrawHL2Box(X,Y,DESC,NUM,F)
	local Enrgy = NUM
		if (LocalPlayer():Alive()) then
			local XPos = X
			local Width, Height	= surface.GetTextSize( Enrgy or "" )
			local YPos = Y
			if (NUM != nil) then
				if (Enrgy<1000) then draw.RoundedBox( 8, XPos, YPos, surface.SScale(108), surface.SScale(36), Color( 0, 0, 0, 150 ) )
				elseif (Enrgy<10000) then draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 23, surface.SScale(36), Color( 0, 0, 0, 150 ) )
				elseif (Enrgy<100000) then draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 46, surface.SScale(36), Color( 0, 0, 0, 150 ) )
				elseif (Enrgy<1000000) then draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 69, surface.SScale(36), Color( 0, 0, 0, 150 ) )
				elseif (Enrgy<10000000) then draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 69 + 23, surface.SScale(36), Color( 0, 0, 0, 150 ) )
				else draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 69 + 46, surface.SScale(36), Color( 0, 0, 0, 150 ) )
				end
			else
				draw.RoundedBox( 8, XPos, YPos, surface.SScale(108) + 38, surface.SScale(36), Color( 0, 0, 0, 150 ) )
			end
			local struc = {}
			struc.pos = {}
			struc.pos[1] = XPos + surface.SScale( 8 )
			struc.pos[2] = Y + surface.SScale(22)
			struc.color = Color(255,220,0,200)
			struc.text = DESC or ""
			struc.font = "HudSelectionText"
			struc.xalign = TEXT_ALIGN_LEFT; struc.yalign = TEXT_ALIGN_LEFT
			draw.Text(struc)
				if NUM!=nil then
				local struc = {}
				struc.pos = {}
				struc.pos[1] = XPos + surface.SScale( 8 ) + surface.SScale( 50 )
				struc.pos[2] = Y + surface.SScale( 2 )
				struc.color = Color(255,220,0,200)
				struc.text = tostring(Enrgy)
				struc.font = F or "HUDIndicatorNumbers"
				struc.xalign = TEXT_ALIGN_LEFT; struc.yalign = TEXT_ALIGN_LEFT
				draw.Text(struc)
			end
			struc = nil
		end
end

local function DrawText(XPos,YPos,TEXT)
		local struc = {}
		struc.pos = {}
		struc.pos[1] = XPos 
		struc.pos[2] = YPos 
		struc.color = Color(255,220,0,200)
		struc.text = string.upper(TEXT or " ")
		struc.font = "HudSelectionText"
		struc.xalign = TEXT_ALIGN_LEFT; struc.yalign = TEXT_ALIGN_LEFT
		draw.Text(struc)
end

local function CartHudPaint()
	local Ener = LocalPlayer():Energy()
	local Health = LocalPlayer():Health()
	local Armor = LocalPlayer():Armor()
	local XPos = surface.SScale(10)
	local YPos = surface.SScale(412)
	if (Health>0) then
		DrawHL2Box(XPos,YPos,"HEALTH",Health)
		if (Armor>0) then
			if (Ener>0) then
				DrawHL2Box(XPos,YPos - 62,"SUIT",Armor)
				DrawHL2Box(XPos,YPos - 124,"HUNGER",Ener)
			else
				DrawHL2Box(XPos,YPos - 62,"SUIT",Armor)
			end
		else
			if (Ener>0) then
				DrawHL2Box(XPos,YPos - 62,"HUNGER",Ener)
			end
		end
		local c1 = LocalPlayer():GetActiveWeapon():Clip1() if c1<0 then c1 = 0 end
		DrawHL2Box(surface.SScale(704), surface.SScale(432) - 62,"AMMO",c1)
		DrawHL2Box(surface.SScale(704), surface.SScale(432),"TOTAL",LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType()))
		draw.RoundedBox( 8, XPos, YPos + surface.SScale(40), surface.SScale(108), surface.SScale(20), Color( 0, 0, 0, 150 ) )
		DrawText(XPos+ surface.SScale( 8 ),YPos+ surface.SScale(47),
		os.date("%H:%M:%S %b %d %Y"))
	end
end

local function CartHud()
	if (gamemode.Call("HUDShouldDraw", "CartHud")==true and LocalPlayer():KeyDown(IN_WALK)) then
		CartHudPaint()
	end
end
hook.Add("HUDPaint", "HUD_CARTHUD", CartHud)

local function ShouldItDraw(Naem)
	if Naem=="CHudHealth" or Naem=="CHudBattery" or Naem=="CHudAmmo" or Naem=="LuaHudEnergy" then
		return false
	end
end
hook.Add("HUDShouldDraw","HUD_CARTHUD_DRAWOTHERSHIT",ShouldItDraw)